package lab.gene.service.impl;

import java.util.Date;
import java.util.List;

import lab.gene.pojo.Gene;
import lab.gene.pojo.GeneMinipre;
import lab.gene.dao.GeneDAO;
import lab.gene.dao.GeneMiniPreDAO;
import lab.gene.service.GeneMinipreService;
import lab.user.dao.UserDAO;
import lab.user.pojo.User;

public class GeneMinipreServiceImpl implements GeneMinipreService {

	@Override
	public GeneMinipre getGeneMinipreByNameAndType(String geneName, String type) {
		// TODO Auto-generated method stub
		GeneMinipre gmnp = null;
		GeneMiniPreDAO dao = new GeneMiniPreDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		gmnp = dao.getGeneMinipreByNameAndType(g, type);
		return gmnp;
	}

	@Override
	public void addGeneMinipre(String geneName, String type, Date recordDate, int colony, float ml, String seqConfirmed, String comments, String userName) {
		// TODO Auto-generated method stub
		UserDAO udao = new UserDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		User u = udao.getUser(userName);
		GeneMiniPreDAO dao = new GeneMiniPreDAO();
		GeneMinipre mini = new GeneMinipre();
		mini.setColony(colony);
		mini.setComments(comments);
		mini.setDateModified(new Date());
		mini.setGene(g);
		mini.setMl(ml);
		mini.setRecordDate(recordDate);
		mini.setSeqConfirmed(seqConfirmed);
		mini.setType(type);
		mini.setUser(u);
		dao.addGeneMinipre(mini);
	}

	@Override
	public List<GeneMinipre> getGeneMinipreHistory(String geneName, String type) {
		List<GeneMinipre> g = null;
		GeneDAO gdao = new GeneDAO();
		Gene gene = gdao.getGene(geneName);
		GeneMiniPreDAO dao = new GeneMiniPreDAO();
		g = dao.getGeneMinipreHistory(gene, type);
		return g;
	}

}
